package com.atguigu.gmall.demo.customer.controller;

import com.atguigu.gmall.demo.customer.bean.Customer;
import com.atguigu.gmall.demo.customer.service.CustomerService;
import com.atguigu.gmall.demo.customer.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController  //标识请求入口类  控制器
public class CustomerController {

    @Autowired
    CustomerService customerService ;

    @RequestMapping("/hello")  //get
    public String  sayHello(@RequestParam("name") String name ,@RequestParam(value = "age" ,required = false,defaultValue = "0") Integer age){
        return "hello world "+name +" age:"+age;   //返回值会包装成response
    }

    @RequestMapping("/customer/{id}.html") //get
    public String  getCustomer(@PathVariable("id") String customerId){

        Customer customer  = customerService.getCustomerById(customerId);
        return "hello world customer:"+customer   ;   //返回值会包装成response
    }

    @PostMapping("/customer")
    public String saveCustomer(@RequestBody  Customer customer){
        System.out.println("保存："+customer);
        return  "success";
    }


}
